package com.qf.main.pharmacy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.common.base.result.ResponseResult;
import com.qf.main.pharmacy.common.vo.AddressVo;
import com.qf.main.pharmacy.entity.Address;
import com.qf.main.pharmacy.service.AddressService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.ws.Service;

/**
 * @author chengqiang
 * @Create 2024-02-18-9:23
 * @Description:
 */
@RestController
@RequestMapping("/address")
@CrossOrigin
@Api(tags = "地址管理")
public class AddressController {
    @Resource
    private AddressService addressService;

    @PostMapping("/save")
    public ResponseResult<Integer> saveAddress(@RequestBody Address address){
        return ResponseResult.success(addressService.saveAddress(address));
    }
    @DeleteMapping("/edit")
    public ResponseResult<Integer> editAddress(@RequestParam("id") Integer id){
        return ResponseResult.success(addressService.removeAddress(id));
    }
    @PutMapping("/erase")
    public ResponseResult<Integer> eraseAddress(@RequestBody Address address){
        return ResponseResult.success(addressService.modifyAddress(address));
    }
    @GetMapping("/list")
    public ResponseResult<Page<Address>> listAddress(@RequestParam("addressUserId") int addressUserId , @RequestParam(value = "pageNum" ,required = false) Integer pageNum, @RequestParam(value = "pageSize" ,required = false) Integer pageSize){
        if(pageNum==null||pageNum==0){
            pageNum=1;
        }
        if(pageSize==null||pageSize==0){
            pageSize=3;
        }
        return ResponseResult.success(addressService.getAddressListById(addressUserId,pageNum,pageSize));
    }
    @GetMapping("/get")
    public ResponseResult<AddressVo> getAddress(@RequestParam("addressId") int addressId){

        return ResponseResult.success(addressService.getAddressById(addressId));
    }


}
